package file;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Created with IntelliJ IDEA
 * Description：字节流读文件
 * User：chenshu
 * Date：2023-11-15
 * Time：14:09
 */
public class Demo1 {
    public static void main(String[] args) throws IOException {
        //打开文件
        InputStream inputStream = new FileInputStream("./test.txt");
        //读文件
//        while (true) {
//            int b = inputStream.read();
//            if (b==-1) {
//                break;
//            }
//            System.out.println(b);
//        }
        byte[] b = new byte[1024];
        int len = inputStream.read(b);
//        System.out.println(len);
//        for (int i = 0; i < len; i++) {
//            System.out.println(b[i]);
//        }
        String s = new String(b,0,len,"utf8");
        System.out.println(s);
        //关闭文件
        inputStream.close();
    }
}
